package EBM.util;

import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class SystemTime {
	
	//系统当前时间
	public static String GetCurrentTime(){		
		Date d = new Date();
		Format time = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		return time.format(d);
	}
	
	//日期天数之差 
	public static String WaitingDays(String oldTime) throws ParseException{
		//系统当前时间
		String time = GetCurrentTime();
		
		SimpleDateFormat dateformat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");    
		Calendar calendar1 = new GregorianCalendar();
		Calendar calendar2 = new GregorianCalendar();
		calendar1.setTime(dateformat.parse(time));
		calendar2.setTime(dateformat.parse(oldTime));
		int year1 = calendar1.get(Calendar.YEAR);
		int year2 = calendar2.get(Calendar.YEAR);
		int days = calendar1.get(Calendar.DAY_OF_YEAR) - calendar2.get(Calendar.DAY_OF_YEAR) + 1;
		if (year1 > year2)
		{
			days += (year1 - year2) * 365 + PrimerYearAdjust(year1, year2);
		}
	
		return String.valueOf(days);
	}
	
	private static int PrimerYearAdjust(int year1, int year2)
	//这个函数并不准确, 可能会有一天的差距. 因为它没有考虑年内具体的月份
	{
		int cnt = 0;
		for(int i = year1; i < year2; i++)
		{
			if(IsPrimerYear(i))
				cnt++;
		}
		return cnt;
	}
	
	private static boolean IsPrimerYear(int year)
	{
		return false;
	}
	
	// Format time "yyyy-MM-dd"
	public static String FormatTime(String time) throws ParseException{
		return time.substring(0,10);
	}
	
//	public static void main(String[] args) throws ParseException{
//		System.out.println(FormatTime("2008-04-19 00:00:00.0"));
//	}
}
